package com.ag.answergames.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Calendar;
import java.util.GregorianCalendar;

@Slf4j
public class MyTimeUtil {
    public static Long getDayBegin() {
        Calendar cal = new GregorianCalendar();
        setZero(cal);
        return cal.getTimeInMillis();
    }

    public static Long getWeekBegin() {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.DAY_OF_WEEK, 1);
        setZero(cal);
        return cal.getTimeInMillis();
    }

    public static Long getMonthBegin() {
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        setZero(cal);
        return cal.getTimeInMillis();
    }

    private static Calendar setZero(Calendar cal) {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        log.debug(cal.getTime().toString());
        return cal;
    }
}
